package com.guigu.buy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.guigu.buy.dto.MerchantUtil;
import com.guigu.buy.pojo.Merchant;
import com.guigu.buy.mapper.MerchantMapper;
import com.guigu.buy.service.IMerchantService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.guigu.buy.utils.PageUtils;
import com.guigu.buy.vo.MerchantVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author com.guigu
 * @since 2024-05-15
 */
@Service
public class MerchantServiceImpl extends ServiceImpl<MerchantMapper, Merchant> implements IMerchantService {
    @Autowired
    private MerchantMapper merchantMapper;

    @Override
    public int insertMerchant(Merchant merchant) {
        return merchantMapper.insertMerchant(merchant);
    }

    @Override
    public List<Merchant> findAllMerchants() {
        return merchantMapper.selectAllMerchants();
    }

    @Override
    public Merchant findMerchantById(Integer id) {
        return merchantMapper.selectMerchantById(id);
    }

    @Override
    public PageUtils<Merchant> audit(int pageNo, int pageSize, MerchantVo vo) {
        QueryWrapper<Merchant> wrapper = new QueryWrapper<>();
        if(vo!=null){
            if(!StringUtils.isEmpty(vo.getMerchantName())){
                wrapper.eq("merchant_name",vo.getMerchantName());
            }
        }

        wrapper.eq("merchant_status",0);
        wrapper.eq("user_merchant_tag",0);
        PageHelper.startPage(pageNo,pageSize);
        List<Merchant> list = this.list(wrapper);
        PageInfo<Merchant> pageInfo = new PageInfo<>(list);
        PageUtils<Merchant> pageUtils = new PageUtils<>();
        pageUtils.setRows(pageInfo.getList());
        pageUtils.setTotal(pageInfo.getTotal());
        return pageUtils;
    }

    @Override
    public PageUtils<Merchant> querylist(int pageNo, int pageSize, MerchantVo vo) {
        QueryWrapper<Merchant> wrapper = new QueryWrapper<>();
        if(vo!=null){
            if(!StringUtils.isEmpty(vo.getMerchantName())){
                wrapper.eq("merchant_name",vo.getMerchantName());
            }
        }

        wrapper.eq("merchant_status",0);
        PageHelper.startPage(pageNo,pageSize);
        List<Merchant> list = this.list(wrapper);
        PageInfo<Merchant> pageInfo = new PageInfo<>(list);
        PageUtils<Merchant> pageUtils = new PageUtils<>();
        pageUtils.setRows(pageInfo.getList());
        pageUtils.setTotal(pageInfo.getTotal());
        return pageUtils;
    }

    @Override
    public PageInfo<MerchantUtil> queryAll(int pageNo, int pageSize, MerchantVo vo) {
        PageHelper.startPage(pageSize,pageNo);
        List<MerchantUtil> list=merchantMapper.query(vo);
        PageInfo<MerchantUtil> pageInfo=new PageInfo<>(list);
        return pageInfo;
    }

}
